package com.jishuo.nontax.api.socket.handle;

import com.jishuo.base.bean.BaseResult;
import com.jishuo.base.util.SpringContextUtil;
import com.jishuo.nontax.api.socket.ApiHandle;
import com.jishuo.nontax.bean.vo.DeductVO;
import com.jishuo.nontax.bfc.service.DeductService;
import org.dom4j.Element;

import java.math.BigDecimal;

/**
 * 批扣接口处理
 * @auther dinggaofei
 * @Date 2023/2/13 13:54
 */
public class DeductApi implements ApiHandle {


    @Override
    public BaseResult execute(String head, Element body) {
        if ("setDeduct".equals(head)){ //学生批扣收款
            DeductVO vo = new DeductVO();
            vo.setPayertypeid(Long.parseLong(body.elementText("payertypeid")));
            vo.setBankaffirm(body.elementText("bankaffirm"));
            vo.setBankstation(body.elementText("bankstation"));
            vo.setAccountcode(body.elementText("accountcode"));
            vo.setAccountdate(body.elementText("accountdata"));
            vo.setAccounttime(body.elementText("accoun ttime"));
            vo.setPayer(body.elementText("payer"));
            vo.setPayeraccountcode(body.elementText("payeraccountcode"));
            vo.setPayeraccountname(body.elementText("payeraccountname"));
            vo.setFund(new BigDecimal(body.elementText("fund")));
            vo.setPostscript(body.elementText("postscript"));
            DeductService deductService  = (DeductService) SpringContextUtil.getBean("deductService");
            BaseResult result = deductService.setDeduct(vo);
           int n  =  result.isSuccess() ? 1:0;
            result.setData("<returninfo>" + n + "</returninfo>");
            return result;
        } else if ("setNewDeduct".equals(head)) {  //学生批扣收款
            DeductVO vo = new DeductVO();
            vo.setUnitid(Long.parseLong(body.elementText("unitid")));
            vo.setCantonid(Long.parseLong(body.elementText("cantonid")));
            vo.setBankaffirm(body.elementText("bankaffirm"));
            vo.setBankstation(body.elementText("bankstation"));
            vo.setAccountcode(body.elementText("accountcode"));
            vo.setAccountdate(body.elementText("accountdate"));
            vo.setAccounttime(body.elementText("accounttime"));
            vo.setPayer(body.elementText("payer"));
            vo.setPayeraccountcode(body.elementText("payeraccountcode"));
            vo.setPayeraccountname(body.elementText("payeraccountname"));
            vo.setFund(new BigDecimal(body.elementText("fund")));
            vo.setPostscript(body.elementText("postscript"));
            DeductService deductService  = (DeductService) SpringContextUtil.getBean("deductService");
            BaseResult result = deductService.setNewDeduct(vo);
            int n  =  result.isSuccess() ? 1:0;
            result.setData("<returninfo>" + n + "</returninfo>");
            return result;

        } else if ("sendDeduct".equals(head)) { // 批扣收入信息
            String accountcode = body.elementText("accountcode");
            String accountdate = body.elementText("accountdate");
            DeductService deductService  = (DeductService) SpringContextUtil.getBean("deductService");
            BaseResult result = deductService.sendDeduct(accountcode,accountdate);
            int n  =  result.isSuccess() ? 1:0;
            result.setData("<returninfo>" + n + "</returninfo>");
            return result;
        }
        return null;
    }
}
